package Demo1;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class AServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out  = response.getWriter();

        // 向AServlet中存储的属性在B中访问,通过这个请求转发器,跳转到b中,调用b的doGet方法,获取这个请求域中的数据
        out.println("范德萨范德萨富士达");
        // getRemoteaddr获取客户端的ip地址
        String ip = request.getRemoteAddr();
        out.println(ip);
        // 动态获取应用的路径
        out.println(request.getContextPath());

        // 获取
        out.println(request.getMethod());

        // 获取请求的URI
        out.println(request.getRequestURI());

        //
        out.println(request.getServletPath());

        //request.getRequestDispatcher("/index.html").forward(request,response);

//        Object value = request.getAttribute("name");
//        out.println(value);
    }
}
